﻿
@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Index.cshtml";
}
<div class="page-container">
    <div class="page-content">

        <div class="titlePanel">
            <div class="title-search">
                <table>
                    <tr>
                        <td style="padding-left: 2px;">
                            <input id="txt_keyword" type="text" class="form-control" placeholder="账户/姓名/手机" style="width: 200px;" />
                        </td>
                        <td style="padding-left: 5px;">
                            <a id="btn_search" class="btn btn-primary btn-sm"><i class="fa fa-search"></i>&nbsp;查询</a>
                        </td>
                    </tr>
                </table>
            </div>
            <div class="toolbar">
                <div class="btn-group">
                    <a id="replace" class="btn btn-default" onclick="reload();"><i class="fa fa-refresh"></i>&nbsp;刷新</a>
                    <a id="add" authorize="yes" class="btn btn-default" onclick="btn_add()"><i class="fa fa-plus"></i>&nbsp;新增</a>
                    <a id="edit" authorize="yes" class="btn btn-default" onclick="btn_edit()"><i class="fa fa-pencil-square-o"></i>&nbsp;编辑</a>
                    <a id="delete" authorize="yes" class="btn btn-default" onclick="btn_delete()"><i class="fa fa-trash-o"></i>&nbsp;删除</a>
                    <a id="revisepassword" authorize="yes" class="btn btn-default" onclick="btn_revisepassword()"><i class="fa fa-key"></i>&nbsp;密码重置</a>
                    <a id="disabled" authorize="yes" class="btn btn-default" onclick="btn_disabled()"><i class="fa fa-toggle-off"></i>&nbsp;禁用</a>
                    <a id="enabled" authorize="yes" class="btn btn-default" onclick="btn_enabled()"><i class="fa fa-toggle-on"></i>&nbsp;启用</a>
                </div>
                <script>$('.toolbar').authorizeButton();</script>
            </div>
        </div>
        <div class="gridPanel">
            <table id="gridTable"></table>
            <div id="gridPager"></div>
        </div>
    </div>
</div>
<script>
    $(function () {
        gridList();
    })
    function gridList() {
        var $gridList = $("#gridTable");
        $gridList.jqGridEx({
            url: "/SystemManage/User/GetGridJson",
            height: $(window).height() - 120,
            colModel: [
                { label: '主键', name: 'Id', hidden: true },
                { label: '账户', name: 'Account', width: 80, align: 'left' },
                { label: '姓名', name: 'RealName', width: 80, align: 'left' },
                {
                    label: '性别', name: 'Gender', width: 60, align: 'center',
                    formatter: function (cellvalue, options, rowObject) {
                        if (cellvalue == true) {
                            return '男';
                        } else {
                            return '女';
                        }
                    }
                },
                { label: '手机', name: 'MobilePhone', width: 90, align: 'left' },
                {
                    label: '公司', name: 'OrganizeId', width: 150, align: 'left',
                    formatter: function (cellvalue, options, rowObject) {
                        return top.clients.organize[cellvalue] == null ? "" : top.clients.organize[cellvalue].fullname;
                    }
                },
                {
                    label: '部门', name: 'DepartmentId', width: 80, align: 'left',
                    formatter: function (cellvalue, options, rowObject) {
                        return top.clients.organize[cellvalue] == null ? "" : top.clients.organize[cellvalue].fullname;
                    }
                },
                {
                    label: '岗位', name: 'DutyId', width: 80, align: 'left',
                    formatter: function (cellvalue, options, rowObject) {
                        return top.clients.duty[cellvalue] == null ? "" : top.clients.duty[cellvalue].fullname;
                    }
                },
                {
                    label: '创建时间', name: 'CreatorTime', width: 80, align: 'left',
                    formatter: "date", formatoptions: { srcformat: 'Y-m-d', newformat: 'Y-m-d' }
                },
                {
                    label: "允许登录", name: "EnabledMark", width: 60, align: "center",
                    formatter: function (cellvalue, options, rowObject) {
                        if (cellvalue == 1) {
                            return '<span class=\"label label-success\">正常</span>';
                        } else if (cellvalue == 0) {
                            return '<span class=\"label label-default\">禁用</span>';
                        }
                    }
                },
                { label: '备注', name: 'Description', width: 200, align: 'left' }
            ],
            pager: "#gridPager",
            sortname: 'DepartmentId asc,CreatorTime desc',
            viewrecords: true
        });
        $("#btn_search").click(function () {
            $gridList.jqGrid('setGridParam', {
                postData: { keyword: $("#txt_keyword").val() },
            }).trigger('reloadGrid');
        });
    }
    function btn_add() {
        $.fn.modalOpen({
            id: "Form",
            title: "新增用户",
            url: "/SystemManage/User/Form",
            width: "700px",
            height: "500px",
            callBack: function (iframeId) {
                top.frames[iframeId].submitForm();
            }
        });
    }
    function btn_edit() {
        var keyValue = $("#gridTable").jqGridRowValue("Id");
        if (checkedRow(keyValue)) {
            $.fn.modalOpen({
                id: "Form",
                title: "修改用户",
                url: "/SystemManage/User/Form?keyValue=" + keyValue,
                width: "700px",
                height: "500px",
                callBack: function (iframeId) {
                    top.frames[iframeId].submitForm();
                }
            });
        }
    }
    function btn_delete() {
        var keyValue = $("#gridTable").jqGridRowValue("Id");
        if (checkedRow(keyValue)) {
            $.fn.deleteForm({
                url: "/SystemManage/User/DeleteForm",
                param: { keyValue: keyValue },
                success: function () {
                    $("#gridTable").resetSelection();
                    $("#gridTable").trigger("reloadGrid");
                }
            })
        } else {
            $.fn.modalMsg('请选择需要删除的数据项！', "warning");
        }
    }
    function btn_details() {
        var keyValue = $("#gridTable").jqGridRowValue("Id");
        if (checkedRow(keyValue)) {
            $.fn.modalOpen({
                id: "Details",
                title: "查看用户",
                url: "/SystemManage/User/Details?keyValue=" + keyValue,
                width: "700px",
                height: "550px",
                btn: null,
            });
        }

    }
    function btn_revisepassword() {
        var keyValue = $("#gridTable").jqGridRowValue("Id");
        var Account = $("#gridTable").jqGridRowValue("Account");
        var RealName = $("#gridTable").jqGridRowValue("RealName");
        if (checkedRow(keyValue)) {
            $.fn.modalOpen({
                id: "RevisePassword",
                title: '重置密码',
                url: '/SystemManage/User/RevisePassword?keyValue=' + keyValue + "&account=" + escape(Account) + '&realName=' + escape(RealName),
                width: "450px",
                height: "255px",
                callBack: function (iframeId) {
                    top.frames[iframeId].submitForm();
                }
            });
        }
    }
    function btn_disabled() {
        var keyValue = $("#gridTable").jqGridRowValue("Id");
        if (checkedRow(keyValue)) {
            $.fn.modalConfirm("注：您确定要【禁用】该项账户吗？", function (r) {
                if (r) {
                    $.fn.submitForm({
                        url: "/SystemManage/User/DisabledAccount",
                        param: { keyValue: keyValue },
                        success: function () {
                            $("#gridTable").resetSelection();
                            $("#gridTable").trigger("reloadGrid");
                        }
                    })
                }
            });
        }
    }
    function btn_enabled() {
        var keyValue = $("#gridTable").jqGridRowValue("Id");
        if (checkedRow(keyValue)) {
            $.fn.modalConfirm("注：您确定要【启用】该项账户吗？", function (r) {
                if (r) {
                    $.fn.submitForm({
                        url: "/SystemManage/User/EnabledAccount",
                        param: { keyValue: keyValue },
                        success: function () {
                            $("#gridTable").resetSelection().trigger("reloadGrid");
                        }
                    })
                }
            });
        }
    }
</script>